package com.hs.sfzy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hs.sfzy.entity.Appointment;
import com.hs.sfzy.mapper.AppointmentMapper;
import com.hs.sfzy.mapper.UserMarkMapper;
import com.hs.sfzy.service.AppointmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @ClassName AppointmentServiceImpl
 * @Description TODO
 * @Author QinKunPeng
 * @Date 2024年10月24日 19:10
 * @Version 1.0
 */
@Service
@Transactional
public class AppointmentServiceImpl implements AppointmentService {

    @Autowired
    AppointmentMapper appointmentMapper;

    @Autowired
    UserMarkMapper userMarkMapper;

    @Override
    public List<Appointment> getAppointments(Map map) {
        return appointmentMapper.getAppointments(map);
    }

    @Override
    public int addAppointment(Appointment appointment) {
        return appointmentMapper.insertAppointment(appointment);
    }

    @Override
    public int deleteAppointment(long id) {
        Appointment appointment = appointmentMapper.getAppointment(id);
        if (appointment != null) {
            userMarkMapper.deleteByAppId(appointment.getId());
            return appointmentMapper.deleteAppointment(id);
        }
        return 0;
    }

    @Override
    public int updateAppointment(Appointment appointment) {
        return appointmentMapper.updateAppointment(appointment);
    }

    @Override
    public Appointment getAppointment(long id) {
        return appointmentMapper.getAppointment(id);
    }

    @Override
    public PageInfo<Appointment> getAppointmentByPage(int pageNum, int pageSize, Map map) {
        PageHelper.startPage(pageNum, pageSize);
        List<Appointment> appointments = appointmentMapper.getAppointments(map);
        return new PageInfo<Appointment>(appointments);
    }

    @Override
    public List<Appointment> findAllY() {
        return appointmentMapper.findAllY();
    }

    @Override
    public List<Appointment> findAllW() {
        return appointmentMapper.findAllW();
    }
}
